package com.example.workmode.Alarm;

import com.example.workmode.MainActivity;
import com.example.workmode.R;
import com.example.workmode.R.drawable;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;

public class PromptUserTask extends BroadcastReceiver {
	
	private int notificationId = 123;
	private String title = "Plan for Today Task";

	@Override
	public void onReceive(Context context, Intent intent) {
		
		Bundle data = intent.getExtras();
		if(data.get("msg").equals("planForToday")) {
			// Send out notification
			NotificationCompat.Builder mBuilder =
			        new NotificationCompat.Builder(context)
			        .setSmallIcon(R.drawable.ic_launcher)
			        .setContentTitle(title);

			Intent resultIntent = new Intent(context, MainActivity.class);

			TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
			stackBuilder.addParentStack(MainActivity.class);
			stackBuilder.addNextIntent(resultIntent);
			PendingIntent resultPendingIntent =
			        stackBuilder.getPendingIntent(
			            0,
			            PendingIntent.FLAG_UPDATE_CURRENT
			        );
			mBuilder.setContentIntent(resultPendingIntent);
			NotificationManager mNotificationManager =
			    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
			mNotificationManager.notify(notificationId, mBuilder.build());
			
			// register alarm manager again
			Intent i = new Intent(context, RegisterAlarm.class);
			i.putExtra("msg", "regAgain");
			context.sendBroadcast(i);
			
		}
		
	}
	
}